﻿using System;

namespace ZQNB.Common.Logs.demo
{
    public class LogDemo
    {

        //---------------关于开关配置----------------
        //<log4net>
        //  <appender name="Trace" type="log4net.Appender.TraceAppender">
        //    <layout type="log4net.Layout.SimpleLayout" />
        //  </appender>

        //  <root>
        //    <level value="OFF" />
        //  </root>

        //  <logger name="ZQNB">
        //    <level value="ALL" />
        //    <appender-ref ref="Trace" />
        //  </logger>
        //</log4net>

        ////enabled
        //var log1 = LogManager.GetLogger("ZQNB.xxx");
        //log1.Debug("a log from ZQNB.xxx -> " + DateTime.Now);
        ////enabled

        ////not enabled
        //var log1 = LogManager.GetLogger("ZQNBxxx");
        //log1.Debug("a log from ZQNBxxx -> " + DateTime.Now);
        ////not enabled

        ////not enabled
        //var log1 = LogManager.GetLogger("abcxxx");
        //log1.Debug("a log from abcxxx -> " + DateTime.Now);
        ////not enabled
        ////---------------关于开关配置----------------
        public void Test()
        {
            ILogger logger = this.GetLogger();
            logger.Debug("from this...");

            var log1 = LoggerManager.GetTheLogger("ZQNB.xxx");
            log1.Debug("a log from ZQNB.xxx -> " + DateTime.Now);

            //bad
            var log2 = LoggerManager.GetTheLogger("ZQNB2");
            log2.Debug("a log from ZQNB2 -> " + DateTime.Now);


            //bad if type not in ZQNB.*
            var log3 = LoggerManager.GetTheLogger("ZQNBxxx");
            log3.Debug("a log from LogDemo.Test() -> " + DateTime.Now);
        }
        public void Test2()
        {
            LoggerManager.SetLoggerManager(new TraceLoggerManager());

            ILogger logger = this.GetLogger();
            logger.Debug("from this...");

            var log1 = LoggerManager.GetTheLogger("ZQNB.xxx");
            log1.Debug("a log from ZQNB.xxx -> " + DateTime.Now);

            //bad
            var log2 = LoggerManager.GetTheLogger("ZQNB2");
            log2.Debug("a log from ZQNB2 -> " + DateTime.Now);


            //bad if type not in ZQNB.*
            var log3 = LoggerManager.GetTheLogger("ZQNBxxx");
            log3.Debug("a log from LogDemo.Test() -> " + DateTime.Now);
        }

        public static void Demo()
        {
            LogDemo deom = new LogDemo();
            deom.Test();
            deom.Test2();
            deom.Test();
        }
    }
}
